var root=ui("$");
var nf = sm("do_Notification");
var app = sm("do_App");
var page = sm("do_Page");
var qqHttp = require("helper/http");
var helperOpen = require("helper/open");
var pubUrl = require("url/pub");
var orderUtil = require("helper/order");
var imgTool = require("helper/picture");
var indexText = ui("indexText");
var string4imgs = "";
var score = 5;//评分
var starList = ui("starList");
var listData = mm("do_ListData");
starList.bindItems(listData);

//评分星星
listData.removeAll();
var starImg=[];
for(var j=0;j<5;j++){
	starImg.push({"starImg":"source://image/common/x_01.png"});
}
listData.addData(starImg);
starList.refreshItems();
//评分
starList.on("touch", function(data) {
	var tag = data + 1;
	score = tag;
	listData.removeAll();
	var starListNew = [];
	for(var m=0;m<tag;m++){
		starListNew.push({"starImg":"source://image/common/x_01.png"});
	}
	for(var n=0;n<5-tag;n++){
		starListNew.push({"starImg":"source://image/common/x_02.png"});
	}
	listData.addData(starListNew);
	starList.refreshItems();
	page.fire("starNum",{"index":indexText.text,"num":score});
});

//商品详情
/*do_ALayout_product.on("touch", function(data){
	var productId = do_ImageView_img.tag;
	helperOpen.open("source://view/mall/product/main.ui", {id : productId});
});*/

/****************处理-图片显示UI-start*****************/
var imgGridView = ui("imgGridView");
var listdataImg = mm("do_ListData");
imgGridView.bindItems(listdataImg);
imgGridView.on("touch",function(data, e){
	listdataImg.removeData([data]);
	imgGridView.refreshItems();
	var imgFiles  = [];
	if(listdataImg && listdataImg.getCount() > 0){
		for(var i=0;i<listdataImg.getCount();i++){
			imgFiles.push(listdataImg.getOne(i).imgPath);
		}
	}
	page.fire("imgFiles0",{"index":indexText.text,"imgFiles":imgFiles});
});
/****************处理-图片显示UI-end*****************/

/****************点击-添加图片-begin*****************/
var addPicItem = ui("addPicItem");
addPicItem.on("touch", function(data, e) {
	var maxCount = 3;
	if(listdataImg.getCount() >= maxCount){
		nf.toast("不能多于3张图片");
		return;
	}
	imgTool.imgMulti(maxCount-listdataImg.getCount(),selectImgBack);//选择多张图片
});

function selectImgBack(imgList){
	listdataImg.addData(
			imgList.map(function(path){
				return {"imgPath" : path}
			})
    );
	imgGridView.refreshItems();
	var imgFiles  = [];
	for(var i=0;i<listdataImg.getCount();i++){
		imgFiles.push(listdataImg.getOne(i).imgPath);
	}
	page.fire("imgFiles0",{"index":indexText.text,"imgFiles":imgFiles});
}
/****************点击-添加图片-end*****************/

/*btnSubmit.on("touch", function(data){
	page.fire("comment_add");
	if(content.text.length == 0){
		nf.toast("评价内容不能为空");
		return;
	}
	if(listdataImg.getCount()>3){
		nf.toast("不能多于3张图片");
		return;
	}
	var imgFiles  = [];
	for(var i=0;i<listdataImg.getCount();i++){
		imgFiles.push(listdataImg.getOne(i).imgPath);
	}
	if(imgFiles.length>0){
		qqHttp.form(imgFiles,"pub/feedback",function(imgDatas){
			string4imgs = imgDatas.path;
			submit();
		});
	}else{
		submit();
	}
	
});*/

/*function submit(){
	page.fire("comment_add");
	var orderType = orderUtil.type.QUANSHOP;
	if (detail.tag) {
		orderType = detail.tag;
	}
	var addParams = {
            orderNo:do_Label_title.tag,
            productId:do_ImageView_img.tag,
			content:content.text,
			img:string4imgs,
			score:score,
            type:orderType
		};
	btnSubmit.enabled = false;
	page.fire("comment_add", ui("do_ALayout_5").tag);
	nf.toast("成功添加评价");
	btnSubmit.enabled = true;
	content.text = '';
	listdataImg.removeAll();*/
	/*qqHttp.post(pubUrl.url.feedback.doAdd,addParams,function(data){
		//移除
		page.fire("comment_add", ui("do_ALayout_5").tag);
		nf.toast("成功添加评价");
		btnSubmit.enabled = true;
		content.text = '';
		listdataImg.removeAll()
	},function(){
		btnSubmit.enabled = true;
	});
}*/